<?php

namespace app\common\model;

use think\Model;

class Video extends Model
{
    // 表名
    protected $name = 'video';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'status_text',
        'is_charge_text'
    ];
    
    public function getStatusList()
    {
        return ['0' => __('Hidden'), '1' => __('Normal')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getIsChargeList()
    {
        return ['0' => __('Free'), '1' => __('Charge')];
    }

    public function getIsChargeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['is_charge'];
        $list = $this->getIsChargeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function collection()
    {
        return $this->belongsTo('VideoCollection', 'collection_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}